As is well known, a solid state drive (SSD) is a data storage device that uses a NAND-based flash memory to store data. The NAND-based flash memory is a non-volatile memory. After data are written to the flash memory, if no power is supplied to the solid state drive, the data are still retained in the solid state drive.
FIG. 1 is a schematic functional block diagram illustrating a conventional solid state drive. As shown in FIG. 1, the solid state drive 10 comprises a controlling unit 101, a temporary storage unit 103, and a flash memory 105. The flash memory 105 is accessible by the controlling unit 101 through an internal bus 107. In addition, the controlling unit 101 is in communication with a host 12 through an external bus 20. Consequently, commands and data can be exchanged between the controlling unit 101 and the host 12. The temporary storage unit 103 is a random access memory for temporarily storing the read date, the write data or the temporary parameter which is required for the controlling unit 101. Moreover, the external bus 20 is a USB bus, an IEEE 1394 bus, an SATA bus, or the like.
Generally, the flash memory 105 comprises plural blocks. Each block comprises plural pages, for example 64 pages. Each page is typically 4K bytes in size. Due to the inherent properties of the flash memory 105, at least one page is written at a time during the writing operation, but a block is erased during the erasing operation.
Generally, each block of the flash memory 105 has limited erase count. If some specified blocks have high erase counts, these blocks are overused and possibly become bad blocks. Under this circumstance, the life span of the flash memory 105 may be reduced. For solving the above drawbacks, a wear leveling technique is disclosed. According to the wear leveling technique, all blocks of the flash memory 105 are averagely used. Consequently, the possibility of causing overuse of specified blocks (i.e. the high erase-count blocks) and generating bad blocks will be reduced. In other words, the used of the wear leveling technique may prolong the life span of the flash memory 105.
The erase counts of all blocks of the flash memory 105 are usually recorded in the solid state drive 10. For performing the wear leveling operation, the conventional solid state drive 10 may judge whether the data in all blocks are hot data (frequently-refreshed data) or cold data (seldom-refreshed data) according to the erase counts of respective blocks. Generally, if the block is frequently erased, the data in the block are frequently refreshed and may be considered as the hot data. Whereas, if the block is seldom erased, the data in the block are seldom refreshed and may be considered as a cold data.
For performing the wear leveling operation, the erase counts of all blocks of the flash memory 105 are firstly detected by the controlling unit 101 of the solid state drive 10. Then, the cold data in the low erase-count block are transferred to the high erase-count block. Then, the low erase-count block is erased as a free block, and thus the storing space of the low erase-count block is released. Then, data are stored into the free block again by the controlling unit 101 during the normal operation. In other words, after the wear leveling operation is performed, the storing space of the low erase-count block is released. By repeatedly using the low erase-count blocks, the erase counts of all blocks of the flash memory 105 are closer to each other. Consequently, all blocks of the flash memory 105 can be averagely used.
However, after the flash memory 105 has been accessed for a long time, almost each block of the flash memory 105 contains some valid data and some invalid data. If the block contains the valid data, the block fails to be erased as the free block. Since the space of the flash memory 105 is occupied by a great number of invalid data, the writable space of the flash memory 105 will gradually reduce. For solving this problem, it is necessary to perform a garbage collection.
FIG. 2 schematically illustrates a conventional process of performing a garbage collection. As shown in FIG. 2, the data D2, D4 and D6 in the block c (Block_c) are invalid data, which are indicated by oblique lines, and the data D1, D3 and D5 in the block c (Block_c) are valid data. In addition, the block d (Block_d) is a free block. While the garbage collection is performed on the block c (Block_c) by the controlling unit 101, the valid data D1, D3 and D5 in the block c (Block_c) are firstly moved to the free block d (Block_d), and all data in the block c (Block_c) are set as invalid data. After the invalid data in the block c (Block_c) are erased, the block c (Block_c) is erased as a new free block. In other words, after the garbage collection is performed, the block c (Block_c) becomes a new free block. Moreover, the block d (Block_d) still has a free space B for storing data.
Generally, before the garbage collection is performed by the solid state drive 10, the controlling unit 101 may determine whether the blocks have to be subject to the garbage collection according to the valid data counts (VAC) of respective blocks. In other words, while the controlling unit 101 starts the garbage collection, the controlling unit 101 should search the number of valid data in all blocks sequentially, and select the blocks with lower valid data counts to be subject to the garbage collection.
In the conventional solid state drive, the garbage collection and the wear leveling operation are independent from each other. For performing the wear leveling operation, the erase counts of the blocks are taken into consideration, and the data in the low erase-count block are transferred to the high erase-count block, so that the erase counts of the blocks are balanced. For performing the garbage collection, the valid data counts of the blocks are taken into consideration, and the data in the block with low valid data count are moved to a free block and then the data in the original block is erased as a new free block, so that the storing space for storing data is released.
However, while the garbage collection or the wear leveling operation is performed, the performance of the solid state drive is largely reduced. Therefore, there is a need of providing a control method for controlling a garbage collection and a wear leveling operation of a solid state drive without obviously reducing the performance of the solid state drive.